import 'package:yqmssa_app/request/http_path.dart';
import 'package:yqmssa_app/request/my_request.dart';
import 'package:yqmssa_app/utils/shared_utils.dart';

class MessageRequest {
  MessageRequest._();

  static Future<List<MessageDM>> systemMsgList([int page = 0]) async {
    final data = {
      "page": page,
      "pagesize": "10",
    };
    final res = await MyRequest().dioReq(HttpPath.systemMsgList, data: data);
    return MessageDM.fromList(res["data"]["data"] ?? []);
  }

  static Future updateIsDistinguish() async {
    final putData = {
      "video_id": "${sharedUtils.service?.id ?? 0}",
    };
    final res = await MyRequest().dioReq(HttpPath.updateIsDistinguish, data: putData);
    return res;
  }
}

class MessageDM {
  MessageDM({
    this.id = "",
    this.createtime = "",
    this.type = "",
    this.typeId = 1,
    this.isRead = 0,
    this.video,
    this.adv,
    this.messageContent = "",
  });

  late final String id;
  late final String createtime;
  late final String type;
  late final int typeId;
  late int isRead;
  late final dynamic video;
  late final dynamic adv;
  late final String messageContent;

  MessageDM.fromJson(Map<String, dynamic> json) {
    id = json['id'].toString();
    createtime = json['createtime'];
    type = json['type'];
    typeId = json['type_id'];
    isRead = json['is_read'];
    video = json['video'];
    adv = json['adv'];
    messageContent = json['message_content'];
  }

  static fromList(List json) {
    return List.generate(json.length, (index) => MessageDM.fromJson(json[index]));
  }
}

class Video {
  late final int id;
  late final String title;
  late final int isJumpMiniprogram;
  late final int isJumpWeb;
  late final int minAge;
  late final String advOrigin;

  Video.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    title = json['title'];
    isJumpMiniprogram = json['is_jump_miniprogram'];
    isJumpWeb = json['is_jump_web'];
    minAge = json['min_age'];
    advOrigin = json['adv_origin'];
  }
}

class Adv {
  late final int id;
  late final String nickname;
  late final String avatar;

  Adv.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    nickname = json['nickname'];
    avatar = json['avatars'];
  }
}
